#!/bin/bash

CFG_DIR=`cat .WKDIR`

POWER_STATUS=`cat .power_status`

clear;


if [ $POWER_STATUS -eq 0 ]; then
    echo "***********************************************************"
    echo "> Camera has already been powered down."
    echo "> NO NEED to power it down again!"
    echo "***********************************************************"
    exit;
elif [ $POWER_STATUS -eq 1 ]; then
    echo "> Camera has not been powered down, it's safe to puwer it down now"
fi

echo ""
echo "> ******************************************************"
echo "> powering down ..."
echo "> using configuration data from dir: ${CFG_DIR}"
echo "> ******************************************************"
echo ""

# AFE
bin/AFE_PW 0

# disable 156MHz clock 
bin/en_156M_clk 0
sleep 1

# DACx0508
bin/dacx0508_cfg ${CFG_DIR}/dacx0508.ini 0

# Daisy Chain
#bin/daisy_cfg ${CFG_DIR}/daisy-3.ini 1
#bin/daisy_cfg ${CFG_DIR}/daisy-2.ini 1
#bin/daisy_cfg ${CFG_DIR}/daisy-1.ini 1
bin/daisy_cfg ${CFG_DIR}/daisy.ini 0


echo ""
echo "> ***************************"
echo "> powering down finished."
echo "> ***************************"
echo ""

# update power status, DON'T remove it
echo 0 > .power_status
